﻿using System;

/* Best practices - Silverlight Documentation excerpt
In most cases, use the predefined exceptions types. Define new exception types only for programmatic scenarios. Introduce a new exception class to enable a programmer to take a different action in code, based on the exception class.

For most applications, derive custom exceptions from the Exception class. 

Include a localized description string in every exception. When the user sees an error message, it is derived from the description string of the exception that was thrown, rather than from the exception class.

Use grammatically correct error messages, including ending punctuation. Each sentence in a description string of an exception should end in a period.

Provide Exception properties for programmatic access. Include extra information in an exception (in addition to the description string) only when there is a programmatic scenario where the additional information is useful.

Return null for extremely common error cases. For example, Open returns null if the file is not found, but throws an exception if the file is locked.

Design classes so that an exception is never thrown in normal use. For example, a FileStream class exposes another way of determining whether the end of the file has been reached. This avoids the exception that is thrown if you read past the end of the file. The following example shows how to read to the end of the file. 

Throw an InvalidOperationException if a property set or method call is not appropriate given the object's Current state.

Throw an ArgumentException or a class derived from ArgumentException if invalid parameters are passed.

The stack trace begins at the statement where the exception is thrown and ends at the catch statement that catches the exception. Be aware of this fact when deciding where to place a throw statement.

Use exception builder methods. It is common for a class to throw the same exception from different places in its implementation. To avoid excessive code, use helper methods that create the exception and return it. 

public class EmployeeListNotFoundException: Exception
{
   public EmployeeListNotFoundException() {   }
   public EmployeeListNotFoundException(string message) : base(message)   {  }
   public EmployeeListNotFoundException(string message, Exception inner)  : base(message, inner)   {  }
}


Here are the built in exceptions  

System..::..SystemException
      System..::..AccessViolationException                 
      System..::..ArgumentException                   <<
      System..::..ArithmeticException
      System..::..ArrayTypeMismatchException
      System..::..BadImageFormatException
      System..::..CannotUnloadAppDomainException
      System.Collections.Generic..::..KeyNotFoundException     <<
      System..::..ContextMarshalException
      System..::..DataMisalignedException
      System..::..ExecutionEngineException
      System..::..FormatException
      System..::..IndexOutOfRangeException            <<
      System..::..InvalidCastException                <<
      System..::..InvalidOperationException           <<
      System..::..InvalidProgramException
      System.IO..::..IOException                      <<
      System..::..MemberAccessException               <<
      System..::..MulticastNotSupportedException
      System..::..NotImplementedException             <<
      System..::..NotSupportedException               <<
      System..::..NullReferenceException              <<
      System..::..OutOfMemoryException
      System..::..RankException
      System.Reflection..::..AmbiguousMatchException
      System.Reflection..::..ReflectionTypeLoadException
      System.Resources..::..MissingManifestResourceException
      System.Runtime.InteropServices..::..ExternalException
      System.Runtime.InteropServices..::..MarshalDirectiveException
      System.Runtime.Serialization..::..SerializationException
      System.Security.Cryptography..::..CryptographicException
      System.Security..::..SecurityException
      System.Security..::..VerificationException
      System.ServiceModel..::..CommunicationException
      System.ServiceModel..::..InvalidMessageContractException
      System.ServiceModel..::..QuotaExceededException
      System..::..StackOverflowException
      System.Threading..::..SynchronizationLockException
      System.Threading..::..ThreadAbortException
      System.Threading..::..ThreadStartException
      System.Threading..::..ThreadStateException
      System..::..TimeoutException                       <<
      System..::..TypeInitializationException            <<
      System..::..TypeLoadException
      System..::..UnauthorizedAccessException
      System.Windows.Markup..::..XamlParseException
      System.Xml..::..XmlException
*/

public class UnanticipatedNullException : Exception
{
   public UnanticipatedNullException() { }
   public UnanticipatedNullException( string message ) : base( message ) { }
   public UnanticipatedNullException( string message, Exception inner ) : base( message, inner ) { }
}

public class ParserException : Exception
{
   public ParserException() { }
   public ParserException( string message ) : base( message ) { }
   public ParserException( string message, Exception inner ) : base( message, inner ) { }
}

public class ConfigException : Exception
{
   public ConfigException() { }
   public ConfigException( string message ) : base( message ) { }
   public ConfigException( string message, Exception inner ) : base( message, inner ) { }
}

public class StateException : Exception
{
   public StateException() { }
   public StateException( string message ) : base( message ) { }
   public StateException( string message, Exception inner ) : base( message, inner ) { }
}